/*
 * Copyright (c) 2022, tyustli
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-02-08     tyustli      first implementation
 */

#include <stdio.h>
#include <math.h>

int bin2dec(int value)
{
    int i = 0;
    int sum = 0;

    while (value != 0)
    {
        sum += (value % 10) * pow(2, i);
        i++;
        value /= 10;
    }

    return sum;
}

int main(int argc, char **argv)
{
    printf("%d to dec is %d\r\n", 11, bin2dec(11));
    printf("%d to dec is %d\r\n", 0, bin2dec(0));
    printf("%d to dec is %d\r\n", 10, bin2dec(10));
    printf("%d to dec is %d\r\n", 1, bin2dec(1));
    printf("%d to dec is %d\r\n", 101, bin2dec(101));
    printf("%d to dec is %d\r\n", 110, bin2dec(110));
    printf("%d to dec is %d\r\n", 1110, bin2dec(1110));
    printf("%d to dec is %d\r\n", 111, bin2dec(111));
    printf("%d to dec is %d\r\n", 1111, bin2dec(1111));

    return 1;
}

/******************** end of file **********************/
